"""
异常基类

"""
import json
from flask import jsonify


class APIException(Exception):  # 修改基类为Exception
    code = 400
    message = 'unexpected error'

    def __init__(self, msg=None, code=None, data=None, headers="application/json"):
        self.headers = headers
        if code:
            self.code = code
        if msg:
            self.message = msg
        self.data = data
        super().__init__(msg)


# 自定义异常
class NotFoundError(APIException):
    code = 10008
    message = '记录未找到'


class PasswordError(APIException):
    code = 10004
    message = '密码错误'


class ConfirmPwdError(APIException):
    code = 10005
    message = '两次输入的新密码不一致'


class ParamsError(APIException):
    code = 10009
    message = '参数不合法'


class MqttError(APIException):
    code = 10010
    message = 'Mqtt连接失败'


class CallBackError(APIException):
    code = 10014
    message = '回调失败'
